package com.prp.gwt.client.widgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;

public class MessageDialogBox extends DialogBox {
	private static MessageDialogBox instance;
	private Button confirmButton = new Button("确认");
	private HTML content = new HTML();

	public static void show(String title, String text) {
		if (instance == null)
			instance = new MessageDialogBox();
		instance.setText(title);
		instance.content.setHTML(text);
		instance.confirmButton.setFocus(true);
		instance.center();
	}

	private MessageDialogBox() {
		VerticalPanel panel = new VerticalPanel();
		panel.setSpacing(10);
		panel.add(content);
		panel.add(confirmButton);
		add(panel);
		confirmButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				hide();
			}
		});
	}
}
